package cn.hesion.wordcount;
/**
 * ClassName: WordReduce <br/>
 * Description: <br/>
 * date: 2021/1/28 16:54<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @program: ClientDemo
 * @description: WordCountReduce
 * @author: hesion
 * @create: 2021-01-28 16:54
 **/
public class WordReduce extends Reducer<Text, IntWritable,Text,IntWritable> {
    // 某一个单词出现的总次数
    int sum;
    IntWritable v = new IntWritable();

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        sum = 0;
        //循环迭代器
        for (IntWritable value : values) {
            sum+=value.get();
        }
        v.set(sum);
        context.write(key,v);
    }
}
